/*
package com.scalar.chiptrack.utils;

import java.util.Properties;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;

public final class SqlQueryMappings {

    private static Properties s_props = new Properties();
    private static String s_queryMappingFile = null;

    static {
        InputStream in = null;
        try {
            s_queryMappingFile = ConfigManager.getSqlQueryMappingFile();
            in = new FileInputStream (s_queryMappingFile);
            s_props.load(in);
        }
        catch (Exception e) {
            System.out.println ("Failed to load SQL Query mappings file, please check \"scalar.properties\" file");
            e.printStackTrace();
        }
        finally {
            if (in != null) {
                try { in.close(); } catch (IOException ignore){}
            }
        }
    }

    private SqlQueryMappings() {
    }

    public static String get (String key) {
        return s_props.getProperty (key);
    }
}
*/

package com.scalar.chiptrack.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.scalar.chiptrack.commons.Constants;

/**
 *
 * @author Balaram Putta
 * @version
 */
public final class SqlQueryMappings {

    private static Properties s_props = new Properties();
    private static Properties s_gpProps = new Properties(); // Balaram, Oct 23, 2003

    static
    {
        String queryMappingFile = null;
        InputStream in = null;

        try
        {
            queryMappingFile = ConfigManager.getSqlQueryMappingFile();
            in = new FileInputStream( queryMappingFile );
            s_props.load( in );
        }
        catch( Exception e )
        {
            System.out.println( "Failed to load SQL Query mappings file, please check \"scalar.properties\" file" );
            e.printStackTrace();
        }
        finally
        {
            if( in != null )
            {
                try
                {
                    queryMappingFile = null;
                    in.close();
                }
                catch( IOException ignore ) { }
            }
        }

        // Load GreatPlainsSQLQueryMapping.properties
        // Balaram, Oct 23, 2003

        /*
        try
        {
            queryMappingFile = ConfigManager.getGreatPlainsSqlQueryMappingFile();
            in = new FileInputStream( queryMappingFile );
            s_gpProps.load( in );
        }
        catch( Exception e )
        {
            System.out.println( "Failed to load Great Plains SQL Query mappings file, please check \"scalar.properties\" file" );
            e.printStackTrace();
        }
        finally
        {
            if( in != null )
            {
                try { in.close(); } catch( IOException ignore ){}
            }
        }
        */
    }

    private SqlQueryMappings()
    {
    }

    public static String get (String key)
    {
        return get( key, Constants.DATASOURCE_TYPE_LOCAL );
    }

    public static String get( String key, int datasourceType )
    {
        String query = null;

        if( datasourceType == Constants.DATASOURCE_TYPE_GREAT_PLAINS )
        {
            query = s_gpProps.getProperty( key );
        }
        else
        {
            query = s_props.getProperty( key );
        }

        return query;
    }
}
